package com.cn.chapter2;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dyvmsapi.model.v20170525.SingleCallByTtsRequest;
import com.aliyuncs.dyvmsapi.model.v20170525.SingleCallByTtsResponse;
import com.aliyuncs.dyvmsapi.model.v20170525.SmartCallRequest;
import com.aliyuncs.dyvmsapi.model.v20170525.SmartCallResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by chenyuncong on 2019/1/17.
 */
public class AICall {
    public static void main(String args[]) throws ClientException {

    }


    public static void call(String accessKeyId,String accessKeySecret,String calledShowNumber,String calledNumber) throws ClientException {
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        //初始化acsClient,暂不支持region化
        final String product = "Dyvmsapi";
        //产品域名（接口地址固定，无需修改）
        final String domain = "dyvmsapi.aliyuncs.com";

        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);
        //组装请求对象-具体描述见控制台-文档部分内容
        SmartCallRequest request = new SmartCallRequest();
        //必填-被叫显号,可在语音控制台中找到所购买的显号
        request.setCalledShowNumber(calledShowNumber);//073182707243
        //必填-被叫号码
        request.setCalledNumber(calledNumber);//13242819353
//        Map<String,String> rmap = new HashMap<>();
//        rmap.put("name","你好啊!小明同学!");
//        request.setVoiceCodeParam(JSON.toJSONString(rmap));
        //必填-语音文件ID
        request.setVoiceCode("e23f34e5-ac07-426b-a35d-08df44b58583.wav");
        //可选-外部扩展字段
        request.setOutId("OutId-test");
        request.setSpeed(1);
        request.setVolume(2);
        request.setMuteTime(10000);
        request.setPauseTime(800);
        request.setActionCodeBreak(false);
        request.setAsrModelId("2070aca1eff146f9a7bc826f1c3d4d31");
        //hint 此处可能会抛出异常，注意catch
        SmartCallResponse smartCallResponse = acsClient.getAcsResponse(request);
        System.out.println("getCallId:"+smartCallResponse.getCallId());
        System.out.println("getCode:"+smartCallResponse.getCode());
        System.out.println("getMessage:"+smartCallResponse.getMessage());
        System.out.println("getRequestId:"+smartCallResponse.getRequestId());

    }
}
